#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1e5+10;

int n,far,t[N];
pii f[N];

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in;for(int i = 1;i <= n;i++) f[i].fi = in,f[i].se = i;
	sort(f+1,f+n+1);
	for(int i = 1;i <= n;i++){
		far = max(far,f[i].se);
		t[i] = max(far - i,1);
	}
	ll ans = 0;
	for(int i = 1;i <= n;i++) ans += max(t[i],t[i-1]);
	printf("%lld\n",ans);
	return 0;
}

